package com.weiweiqin.controller.back;

import com.weiweiqin.model.Customer;
import com.weiweiqin.model.Paylog;
import com.weiweiqin.service.PaylogService;
import com.weiweiqin.vo.common.CustomerTabVO;
import com.weiweiqin.vo.common.Page;
import com.weiweiqin.vo.common.PaylogTabVO;
import com.weiweiqin.vo.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("admin/paylog")
public class PaylogController {

	@Autowired
	private PaylogService paylogService;

	private static final Logger logger = LoggerFactory
			.getLogger(PaylogController.class);
	@RequestMapping(value = "/pageList.do", method = { RequestMethod.POST,
			RequestMethod.GET })
	@ResponseBody
	public String pageList(int currPage){
		Result result = new Result();
		Page page = new Page();
		page.setCurrPage(currPage);
		Map<String,Object> conditions = new HashMap<String, Object>();
		List<Paylog> paylogList = paylogService.pageList(page, conditions);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		List<PaylogTabVO> voList = new ArrayList<PaylogTabVO>();
		if(null != paylogList && !paylogList.isEmpty()){
			for (Paylog paylog : paylogList) {
				PaylogTabVO vo = new PaylogTabVO();
				vo.setPaylog(paylog);
				String format = sdf.format(paylog.getCreateTime());
				vo.setCreateTime(format);
				if(null != paylog.getPayTime()) {
					String format1 = sdf.format(paylog.getPayTime());
					vo.setPayTime(format1);
				}

				voList.add(vo);
			}
		}
		int totalCount = paylogService.totalCount(conditions);
		page.setTotalCount(totalCount);
		Map<String,Object> mp = new HashMap<String,Object>();
		mp.put("totalCount",page.getTotalCount());
		mp.put("list", voList);
		result.setObj(mp);
		result.setResult(true);
		return result.toJson();
	}

}
